#coding=utf-8
#伪装成浏览器来爬网页,并把爬取的网页写到本地

import urllib.request

def save_file(data):
    save_path=r'G:\Python\homework\baowen\test.txt'
    f_obj=open(save_path,'wb') #wb 表示打开方式
    f_obj.write(data)
    f_obj.close()

weburl=r'http://user.qzone.qq.com/716282978/infocenter?ptsig=NgNOUFNulecdAmeKF1hDdrL4h2G-tCw4z7JMkHQWZ6k_'
webheader={'User-Agent':'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36'}
req=urllib.request.Request(url=weburl,headers=webheader)
webPage=urllib.request.urlopen(req)
data=webPage.read()
save_file(data)
data=data.decode('gbk',"ignore")
print(data)
